package com.house.service.impl;

import com.house.entity.Users;
import com.house.entity.UsersExample;
import com.house.mapper.UsersMapper;
import com.house.service.UsersService;
import com.house.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl  implements UsersService {
    @Autowired(required = false)
    private UsersMapper usersMapper;
    @Override
    public int UserService(Users users) {
        users.setPassword(MD5Utils.md5Encrypt(users.getPassword()));
        //使用MD5  进行密码加迷
        return this.usersMapper.insertSelective(users);
    }

    @Override
    public Users userLogin(String name, String password) {
        UsersExample usersExample=new UsersExample();
        UsersExample.Criteria criteria = usersExample.createCriteria();
        criteria.andNameEqualTo(name);
       criteria.andPasswordEqualTo(password);
        List<Users> users = this.usersMapper.selectByExample(usersExample);
        if(users!=null&&users.size()==1){

            return users.get(0);
        }
        return null;
    }

    @Override
    public Users userLogins(String name) {
        UsersExample usersExample=new UsersExample();
        UsersExample.Criteria criteria = usersExample.createCriteria();
        criteria.andNameEqualTo(name);
        List<Users> users = this.usersMapper.selectByExample(usersExample);
        if(users!=null&&users.size()==1){
              return users.get(0);

        }
        return null;
    }

}
